package com.lanou3g.hw0514.study;

import org.junit.Test;

import java.util.UUID;

/**
 * Created by dllo on 18/5/15.
 */
public class TestUUID {
    @Test
    //哪个地方加上test就可以直接运行该方法
    public void fun() {
        String uuid = UUID.randomUUID().toString();
        System.out.println(uuid);
    }

    public static String getRandomString() {
        String uuid = UUID.randomUUID()
                .toString()//转换成字符串
                .replace("-", "")//去掉短线
                .toUpperCase();//转换成大写字母
        return uuid;
    }

    //aaa.png=>uuid.png
    public static String handleFileName(String filename) {
        String name = getRandomString();//获取uuid
        //找到最后一个.的下标
        int lastIndex = filename.lastIndexOf(".");
        String expand = filename.substring(lastIndex, filename.length());
        return name + expand;//拼接成新的文件名
    }

    @Test
    public void test01() {
        String newName = handleFileName("aaa.png");
        System.out.println(newName);
    }
}
